home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
WLIST.ARJ
/
MISC.H
< prev
Wrap
Text File
|
1992-05-15
|
5KB
|
159 lines
#ifndef MiscIncluded
#define MiscIncluded
// one big header file for miscelaneous odds n ends
// this file is generally included by all other header files
typedef char Char;
typedef unsigned char Bool;
typedef unsigned char Byte;
typedef signed char SByte;
typedef unsigned short Word;
typedef signed short SWord;
typedef unsigned int Int; // avoid using this: provided for overloaded libarary consistancy
typedef signed int SInt; // avoid using this: provided for overloaded libarary consistancy
typedef unsigned long Long;
typedef signed long SLong;
typedef float Float; // for consistancy
typedef double Double;
typedef Byte* BytePointer; // I use it in a few places...
// constants related to above types. The Size of these things will stay the
// same from system to system.
const Char MaxChar = 255;
const Byte MaxByte = 255;
const SByte MaxSByte = 127;
const SByte MinSByte = (-128);
const Word MaxWord = 0xFFFF;
const SWord MaxSWord = 32767;
const SWord MinSWord = 0x8000; // (-32768);
const SLong MaxSLong = 0x7FFFFFFFL; // 2147483647;
const Long MaxLong = 0xFFFFFFFFL;
const SLong MinSLong = 0x80000000L; // (-2147483648);
const Bool True = 1;
const Bool False = 0;
const Bool Yes = 1;
const Bool No = 0;
const Bool On = 1;
const Bool Off = 0;
/* the following have values < 0 so that they may be used as alternatives to
text placement rountines that need positive values */
const SWord Left=(MinSWord+1);
const SWord Center=(MinSWord+2);
const SWord Right=(MinSWord+3);
const Word NotFound=MaxWord;
const Long VecObjNotFound=MaxLong;
// used with some search functions.
/* misc. macros */
SByte Abs(SByte x);
SWord Abs(SWord x);
SInt Abs(SInt x);
SLong Abs(SLong x);
Float Abs(Float x);
Double Abs(Double x);
Byte Max(Byte a, Byte b );
SByte Max(SByte a, SByte b );
Word Max(Word a, Word b );
SWord Max(SWord a, SWord b );
Int Max(Int a, Int b );
SInt Max(SInt a, SInt b );
Long Max(Long a, Long b );
SLong Max(SLong a, SLong b );
double Max(double a, double b);
Byte Min(Byte a, Byte b );
SByte Min(SByte a, SByte b );
Word Min(Word a, Word b );
SWord Min(SWord a, SWord b );
Int Min(Int a, Int b );
SInt Min(SInt a, SInt b );
Long Min(Long a, Long b );
SLong Min(SLong a, SLong b );
double Min(double a, double b);
Bool InRange(Byte Val, Byte Low, Byte High);
Bool InRange(SByte Val, SByte Low, SByte High);
Bool InRange(Word Val, Word Low, Word High);
Bool InRange(SWord Val, SWord Low, SWord High);
Bool InRange(Int Val, Int Low, Int High);
Bool InRange(SInt Val, SInt Low, SInt High);
Bool InRange(Long Val, Long Low, Long High);
Bool InRange(SLong Val, SLong Low, SLong High);
Bool InRange(double Val, double Low, double High);
Bool InRange(long double Val, long double Low, long double High);
SLong Round(double Val); // .2 => 0 .7 => 1 -.2 => 0 -.7 => -1
SLong RoundUp(double Val); // .2 => 1 .7 => 1 -.2 => 0 -.7 => 0
SLong RoundDown(double Val); // .2 => 0 .7 => 0 -.2 => -1 -.7 => -1
SLong RoundOut(double Val); // .2 => 1 .7 => 1 -.2 => -1 -.7 => -1
SLong RoundIn(double Val); // .2 => 0 .7 => 0 -.2 => 0 -.7 => 0
Char ToUpper(Char C);
Char ToLower(Char C);
void PigeonHole(Long TotQuan, Word ArrayLen, Word A[]);
// spreads TotQuan as evenly as possible over A
Long SystemTick(); // returns the current system tick
#include <dos.h>
inline void Delay(Word MilliSecs) {delay(MilliSecs);}
void Sound(float Pitch,Word MilliSecs);
// a little bit of control over the pc speaker
void Beep(Byte Num=1);
// Num is the number of beeps ya want
#define Randomize() srand((int) time(NULL))
// Initializes (seeds) the random number generator
#define Random(Max) (Word(rand() % Max))
// returns a random integer in the range of 0 to Max excluding Max
#define DebugPause(Msg) {puts(Msg "\n"); Delay(2500); }
// prints the message and then pauses a bit. Used in debugging
#define CopyArray(Dest,Source) memcpy(Dest,Source,sizeof(Dest))
// Dest must be something that sizeof will work on
#define CopyString(Dest,Source) (strncpy(Dest,Source,sizeof(Dest)-1),Dest[sizeof(Dest)-1]=0)
// For the type (Char*,Char*) Dest must be something that sizeof will work on
#define ClearStruct(A) memset((void*)(&A),0,sizeof(A))
// fill a struct with zeros
#define ClearArray(A) memset(A,0,sizeof(A))
/* fill an array with zeros. Array must be defined so that sizeof will
work on it */
// Given these objects, standard CRC16 will be calculated
Word CRC(void* P,Long Size);
Word CRC(const Char* S);
#define Loop while(1)
// structure for an infinite loop
#define For(TheVar,TheEnd) for(TheVar=0;TheVar<TheEnd;TheVar++)
// Makes for a simpler, more readable, less error prone loop.
// Use "For(I,10)" instead of "for(I=0;I<10;I++)"
typedef void (* VanillaFunctionPtr)(void);
typedef void (* VoidFuncPtr)(void);
typedef Bool (* BoolFuncPtr)(void);
void FatalError(const Char*);
#endif